package com.demo.mapper;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;

import java.io.IOException;

/**
 * @author cxx
 * @create 2020-02-15 13:06
 **/
public class WordCountMapper extends TableMapper<Text,IntWritable> {

    @Override
    protected void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException {
        String values = Bytes.toString (value.getValue (Bytes.toBytes ("content"), Bytes.toBytes ("info")));
        String[] split = values.split (" ");
        for (String str : split) {
            context.write (new Text(str),new IntWritable (1));
        }
    }
}
